<template>
  <div style="height:100%;width:100%;position:relative;">
    <div class="pagetop" ref="buttondiv">
      <table style="width:100%">
        <tr>
          <td width="2000px"></td>
          <td style="text-align:right">
            <el-button @click="findList(), isFirstLoading = false, NewArr = [], UpdateArr = []" type="primary"
              icon="el-icon-search" v-has="'PINQUERY'">查询</el-button>
          </td>
          <td style="text-align:right">
            <el-button @click="OpenDialog(1)" icon="el-icon-plus" v-has="'PADD'">新增</el-button>
          </td>
          <td style="text-align:right">
            <el-button @click="OpenDialog(2)" icon="el-icon-edit" v-has="'PMODIFY'">修改</el-button>
          </td>
          <td style="text-align:right">
            <el-button @click="OpenDialog(3)" icon="el-icon-delete" v-has="'PDELETE'">删除</el-button>
          </td>
          <td style="text-align:right">
            <el-button @click="ExportCsv()" icon="el-icon-files" v-has="'PEXPORT'">导出</el-button>
          </td>
        </tr>
      </table>
    </div>
    <div class="pagecenter">
      <div class="middle-center" ref="xTableDiv" style="height:100%;">
        <vxe-table :data="tableData" :loading="loading" :keyboard-config="keyConfig"
          :keyboard-local-config="keyLocalConfig" :row-class-name="rowClassName" :select-config="selectConfig"
          :sort-config="{ trigger: 'cell' }" @current-change="currentChangeEvent" border fit height="auto"
          header-align="center" highlight-current-row highlight-hover-row highlight-hover-column ref="xTable" resizable
          show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
          <vxe-table-column key="bindmode" field="bindmode" title="合并方式" width="80px" sortable
            align="center"></vxe-table-column>
          <vxe-table-column key="mdlname" field="mdlname" title="模板名称" width="120px" sortable></vxe-table-column>
          <vxe-table-column key="rpt_itemname" field="rpt_itemname" title="合并前项目(同项)目标标本项目(异项)" width="160px"
            sortable></vxe-table-column>
          <vxe-table-column key="rpt_itemcode" field="rpt_itemcode" title="项目代码" width="100px"
            sortable></vxe-table-column>
          <vxe-table-column key="description" field="description" title="描述" width="120px" sortable></vxe-table-column>
          <vxe-table-column key="invalid" field="invalid" title="停用" width="40px" sortable align="center">
            <template v-slot="{ row }">
              <el-checkbox false-label="" true-label="停用" v-model="row.invalid" disabled></el-checkbox>
            </template>
          </vxe-table-column>
          <vxe-table-column key="inputcode" field="inputcode" title="输入码" width="80px" sortable></vxe-table-column>
          <vxe-table-column key="bindmdlid" field="bindmdlid" title="合并模板ID" width="60px" sortable align="right"
            header-align="center"></vxe-table-column>
          <vxe-table-column key="keepinold" field="keepinold" title="在原报告中保留项目" width="60px" sortable align="center">
            <template v-slot="{ row }">
              <el-checkbox false-label="否" true-label="是" v-model="row.keepinold" disabled></el-checkbox>
            </template>
          </vxe-table-column>
          <vxe-table-column key="seq" field="seq" title="序号" width="60px" sortable align="center"></vxe-table-column>
        </vxe-table>
      </div>
      <div class="middle-right">
        <el-tabs @tab-click="handleTabClick" style="height:100%;" type="border-card" ref="tabs">
          <el-tab-pane label="基本信息">
            <el-form :inline="true" :model="bindMdlright" @submit.native.prevent label-width="auto" ref="form">
              <table height="100%" style="border-spacing:5px 10px;width:100%">
                <tr>
                  <td>合并模板ID： </td>
                  <td colspan="3">
                    <el-input v-model="bindMdlright.bindmdlid" readonly></el-input>
                  </td>
                </tr>
                <tr>
                  <td style="width:100px">合并方式： </td>
                  <td colspan="3" style="width:200px">
                    <el-input v-model="bindMdlright.bindmode" readonly></el-input>
                  </td>

                </tr>
                <tr>
                  <td><span style="color:#F56C6C">模板名称： </span></td>
                  <td colspan="3">
                    <el-input v-model="bindMdlright.mdlname" readonly></el-input>
                  </td>
                </tr>
                <tr>
                  <td>
                    <span v-if="bindMdl.bindmode == '同项合并'" style="color:#F56C6C">合并前项目：</span>
                    <span style="color:#F56C6C" v-else>合并前项目：</span>
                  </td>
                  <td colspan="3">
                    <el-input v-model="bindMdlright.rpt_itemname" readonly></el-input>
                  </td>
                </tr>
                <tr>
                  <td>序号： </td>
                  <td colspan="3">
                    <el-input v-model="bindMdlright.seq" readonly></el-input>
                  </td>
                </tr>
                <tr>
                  <td>是否停用： </td>
                  <td>
                    <el-checkbox label="" disabled v-model="bindMdlright.invalidflag"></el-checkbox>
                  </td>
                </tr>
                <tr>
                  <td>在原标本中保留项目： </td>
                  <td>
                    <el-checkbox label="" disabled v-model="bindMdlright.keepinoldflag"></el-checkbox>
                  </td>
                </tr>
                <tr>
                  <td style="vertical-align:top">描述： </td>
                  <td colspan="3">
                    <el-input type="textarea" :rows="3" v-model="bindMdlright.description" readonly></el-input>
                  </td>
                </tr>
                <tr>
                  <td>输入码： </td>
                  <td colspan="3">
                    <el-input v-model="bindMdlright.inputcode" readonly></el-input>
                  </td>
                </tr>
              </table>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="合并模板明细" ref="tabs2">
            <div ref="xTableDiv1" style="height:100%">
              <vxe-table :data.sync="tableDataDetail" :select-config="selectConfig" height="auto"
                :sort-config="{ trigger: 'cell' }" :loading="loadingDetail" :row-class-name="DetailClassName"
                highlight-current-row highlight-hover-row border fit highlight-hover-column resizable
                header-align="center" show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
                <vxe-table-column key="rpt_itemcode" field="rpt_itemcode" title="项目代码" width="100px"></vxe-table-column>
                <vxe-table-column key="rpt_itemname" field="rpt_itemname" :title="itemnametable"
                  width="120px"></vxe-table-column>
                <vxe-table-column key="seq" field="seq" title="序号" width="60px" align="center"></vxe-table-column>
                <vxe-table-column key="invalid" field="invalid" title="停用" width="60px" align="center">
                  <template v-slot="{ row }">
                    <el-checkbox false-label="" true-label="停用" v-model="row.invalid" disabled></el-checkbox>
                  </template>
                </vxe-table-column>
              </vxe-table>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
    <el-dialog v-el-drag-dialog :close-on-click-modal="false" :title="dialogtitle" :visible.sync="dialogFormVisible"
      @close="CancelTips()" v-if="dialogif" width="650px" style="padding:5px 5px 5px 5px" top="6vh">
      <div v-if="actionflag < 3">
        <el-form :inline="true" :model="bindMdl" @submit.native.prevent label-width="auto" ref="form">
          <table height="100%" style="width:100%;border:1px solid #ccc;border-bottom:0">
            <tr>
              <td width="100">合并模板ID</td>
              <td colspan="2">
                <el-input style="width:100%;" v-model="bindMdl.bindmdlid" disabled=""></el-input>
              </td>
              <td style="text-align:center;border:1px solid #ccc" rowspan="2">
                <table>
                  <tr>
                    <td>
                      <el-radio v-model="bindMdl.bindmode" label="同项合并" size="small"
                        @change="bindmodeChange($event)">同项合并</el-radio>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <el-radio v-model="bindMdl.bindmode" label="异项合并" size="small"
                        @change="bindmodeChange($event)">异项合并</el-radio>
                    </td>
                  </tr>
                </table>
              </td>
            </tr>
            <tr>
              <td><span style="color:#F56C6C">模板名称</span></td>
              <td colspan="2">
                <el-input style="width:100%;" v-model="bindMdl.mdlname" @input="mdlnameChange" ref="inputmdlname"
                  @keyup.enter.native="autofocusEvent($event, 'mdlname')"></el-input>
              </td>
            </tr>
            <tr>
              <td><span style="color:#F56C6C">{{ itemname }}</span></td>
              <td colspan="2">
                <rm-ddl-rptitem prgno="LIS115" :appendtobody="true" v-model="bindMdl.rpt_itemcode" ref="inputrptitem"
                  @keyup.enter.native="autofocusEvent($event, 'rptitem')"></rm-ddl-rptitem>
              </td>
              <td style="text-align:left">
                <el-checkbox label="停用" v-model="bindMdl.invalid"></el-checkbox>
              </td>
            </tr>
            <tr>
              <td>序号</td>
              <td colspan="2">
                <el-input style="width:100%;" v-model="bindMdl.seq" @keyup.enter.native="autofocusEvent($event, 'seq')"
                  ref="inputseq"></el-input>
              </td>
              <td style="text-align:left">
                <el-checkbox label="在原标本中保留项目" v-model="bindMdl.keepinold"></el-checkbox>
              </td>
            </tr>
            <tr>
              <td>描述</td>
              <td colspan="3">
                <el-input :rows="3" type="textarea" v-model="bindMdl.description" ref="inputdesc"></el-input>
              </td>
            </tr>
            <tr>
              <td>输入码</td>
              <td>
                <el-input v-model="bindMdl.inputcode" ref="inputincode"></el-input>
              </td>

            </tr>
          </table>
          <div ref="xTableDiv3">
            <vxe-table :data.sync="tableDataDetailEdit" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }"
              :sort-config="{ trigger: 'cell' }" :mouse-config="{ selected: true }" :select-config="selectConfig"
              :keyboard-config="keyConfig" @edit-closed="containeditclose" height="350px" highlight-current-row
              highlight-hover-row border ref="xTable3" resizable highlight-hover-column show-header-overflow="tooltip"
              show-overflow="tooltip" header-align="center" :loading="loadingDetailEdit" size="mini" stripe width="980px">

              <vxe-table-column field="rpt_itemcode" key="rpt_itemcode" :title="itemnametable" width="220px">
                <template v-slot="{ row, rowIndex }">
                  <rm-ddl-rptitem prgno="LIS115" :appendtobody="true" :value="row.rpt_itemcode"
                    @change="RptChangeEvent($event, row, rowIndex)"
                    @keyup.enter.native="autofocusEvent($event, 'childrptitem', row, rowIndex)" @click.native="rptfocus"
                    width="200px"></rm-ddl-rptitem>
                </template>
              </vxe-table-column>
              <vxe-table-column field="invalid" key="invalid" title="停用" width="60px" align="center">
                <template v-slot="{ row, rowIndex }">
                  <el-checkbox v-model="row.invalid"
                    @keyup.enter.native="autofocusEvent($event, 'invalid', row, rowIndex)"></el-checkbox>
                </template>
              </vxe-table-column>
              <vxe-table-column :edit-render="{ name: 'input', autoselect: true }" field="seq" key="seq" title="序号"
                width="80px" sortable align="center"></vxe-table-column>
            </vxe-table>
          </div>
        </el-form>
        <div class="dialog-footer" slot="footer" style="text-align:right">
          <div style="margin-top: 3px">
            <el-button @click="AddRecord()" icon="el-icon-plus">新增明细</el-button>
            <el-button @click="DelRecord()" icon="el-icon-delete">删除明细</el-button>
            <el-button @click="CommitTips()">确 定</el-button>
            <el-button @click="CancelTips()">取 消</el-button>
          </div>
          <!-- <table style="margin-left:266px">
                      <tr>
                          <td>
                              <el-button @click="AddRecord()" icon="el-icon-plus">新增明细</el-button>
                          </td>
                          <td>
                              <el-button @click="DelRecord()" icon="el-icon-delete">删除明细</el-button>
                          </td>
                          <td>
                              <el-button @click="CommitTips()">确 定</el-button>
                          </td>
                          <td>
                              <el-button @click="CancelTips()">取 消</el-button>
                          </td>

                      </tr>
                  </table> -->
        </div>
      </div>
      <div style="margin-left:260px" v-else>
        <span class="dialog-footer" slot="footer">
          <el-button @click="CommitTips()">确 定</el-button>
          <el-button @click="CancelTips()">取 消</el-button>
        </span>
      </div>
    </el-dialog>
    <el-dialog v-el-drag-dialog :close-on-click-modal="false" title="提示" :visible.sync="dialogVisible" width="30%">
      <div class="el-message-box__status el-icon-warning"></div>
      <div class="el-message-box__message" style="padding-top:24px">
        <p>确定要删除合并模板记录<b style="color:red">{{ Delmdlname }}</b>吗?</p>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="CommitTips()">确 定</el-button>
        <el-button @click="CancelTips()">取 消</el-button>
      </span>
    </el-dialog>

  </div>
</template>


<script>
export default {
  name: "LIS115",
  data() {
    return {
      loading: false,
      loadingDetail: false,
      loadingDetailEdit: false,
      buttonwidth: "",
      keyConfig: {
        isDel: true,
        isTab: true,
        isEdit: true
      },
      keyLocalConfig: {
        isArrow: true
      },
      bindMdl: {},
      tempbindMdl: {},
      tempRowIndex: 0,
      selectConfig: { tigger: "row" },
      actionflag: 0,
      dialogFormVisible: false,
      dialogVisible: false,
      dialogif: true,
      DelIndex: -1,
      Delmdlname: "",
      rptfocusflag: false,

      tableData: [],
      tableDataDetail: [],
      tableDataDetailEdit: [],
      tableColumnDetailEdit: [],
      tableColumn: [],
      tableColumnDetail: [],
      tableColumnUnit: [],
      dialogtitle: "",
      CotainAddNum: 0,
      isFirstLoading: true,
      AddArray: 0,
      bindMdlright: {},
      curtabindex: 1,
      itemname: "合并前项目",
      itemnametable: "合并后报告项目",
      xtable3index: 0,
      NewArr: [],
      UpdateArr: []
    };
  },
  created() {
    this.findList();
  },
  mounted() { },
  updated() {
    this.getButtonWidth();
    if (this.isFirstLoading) {
      var selectrow = {};
      if (this.AddArray > 0) {
        selectrow = this.$refs.xTable.tableData.filter(item => {
          return item.bindmdlid == this.AddArray;
        })[0];
      } else {
        if (this.tempRowIndex > 0) selectrow = this.$refs.xTable.getData(this.tempRowIndex);
        else selectrow = this.$refs.xTable.getData(0);
      }
      if (selectrow) {
        this.isFirstLoading = false;
        this.$nextTick(() => {
          this.$refs.xTable.setCurrentRow(selectrow);
          this.bindMdlright = selectrow;
          this.Delmdlname = selectrow.mdlname;
          this.$refs.xTable.scrollToRow(selectrow);
        });
      }
    }
  },
  methods: {
    currentChangeEvent({ row }) {
      this.bindMdlright = row;
      this.Delmdlname = row.mdlname;
      this.tempRowIndex = this.$refs.xTable.getRowIndex(row);
      this.itemnametable = row.bindmode == "同项合并" ? "合并后项目" : "参与合并项目";
      if (this.curtabindex == 1) {
        this.ShowDetail();
      }
    },
    getButtonWidth() {
      if (this.$refs.buttondiv) {
        this.buttonwidth = this.$refs.buttondiv.offsetWidth - 100 + "px";
      }
    },
    rowClassName({ row, rowIndex }) {
      if (this.NewArr.indexOf(row.bindmdlid + "") > -1) {
        return "Add";
      }
      if (this.UpdateArr.indexOf(row.bindmdlid + "") > -1) {
        return "Update";
      }
      if (row.invalid.length > 0) {
        return "rm-alert";
      }
    },
    DetailClassName({ row, rowIndex }) {
      if (row.invalid.length > 0) {
        return "rm-alert";
      }
    },
    OpenDialog(flag) {
      // this.showtempMdl = JSON.parse(JSON.stringify(this.bindMdl));
      this.actionflag = flag;
      if (flag == 1) {
        this.bindMdl = { bindmode: "同项合并" };
        this.tableDataDetailEdit = [];
        this.dialogtitle = "新增单项输入模板";
        this.dialogif = true;
        this.dialogFormVisible = true;
        this.CotainAddNum = 0;
        this.$nextTick(() => {
          this.$refs.inputmdlname.$refs.input.focus();
        });
      }
      if (flag == 2) {
        if (this.bindMdlright && this.bindMdlright.bindmdlid && this.bindMdlright.bindmdlid != 0) {
          if (this.$ddldata.IsAreaMode && this.$tool.getSession(this.$tool.loginutype) != "G" && this.bindMdlright.hospcode == "All") {
            this.$confirm("只有管理员才能修改所有医院数据!", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              focusCancelButton: true,
              closeOnClickModal: false,
              type: "warning"
            });
          } else {
            this.FindmdlAndDetail();
            this.dialogtitle = "修改单项输入模板";
          }
        } else {
          this.$message("请先选择一条需要修改的数据");
        }
      }
      if (flag == 3) {
        if (this.bindMdlright && this.bindMdlright.bindmdlid && this.bindMdlright.bindmdlid != 0) {
          this.dialogVisible = true;
        } else {
          this.$message("请先选择一条需要删除的数据");
        }
      }
      this.DelIndex = -1;
    },
    CancelTips() {
      if (this.actionflag < 3) {
        this.dialogif = false;
        this.dialogFormVisible = false;
        this.CotainAddNum = 0;
      } else {
        this.dialogVisible = false;
      }
    },
    CommitTips() {
      if (this.actionflag < 3) {
        if (this.bindMdl.mdlname == "" || this.bindMdl.rpt_itemcode == "") {
          this.$refs.inputmdlname.focus();
          this.$message("模板名称和报告项目不能为空！");
          return false;
        }
      } else {
      }
      this.SaveRecord();
    },
    FindmdlAndDetail() {
      this.loadingDetailEdit = true;
      var mdlid = 0;
      if (this.bindMdlright.bindmdlid) mdlid = this.bindMdlright.bindmdlid;
      else mdlid = 0;
      this.$tool
        .request({
          url: "LIS/LIS1/LIS115",
          method: "post",
          data: {
            action: "queryforupdate",
            bindmdlid: mdlid
          }
        })
        .then(res => {
          var upmdl = res.Data1[0];
          this.tempbindMdl = JSON.parse(JSON.stringify(res.Data1[0]));
          this.bindMdl = upmdl;
          this.bindMdl.invalid = this.bindMdl.invalid == "1" ? true : false;
          this.bindMdl.keepinold = this.bindMdl.keepinold == "1" ? true : false;
          this.bindMdl.bindmode = this.bindMdl.bindmode == "1" ? "同项合并" : "异项合并";
          this.tableDataDetailEdit = res.Data2;
          for (var i = 0; i < this.tableDataDetailEdit.length; i++) {
            this.tableDataDetailEdit[i].invalid = this.tableDataDetailEdit[i].invalid > 0 ? true : false;
          }
          this.CotainAddNum = res.Data2.length;
          this.loadingDetailEdit = false;
          this.dialogif = true;
          this.dialogFormVisible = true;
          this.tempRowIndex = this.$refs.xTable.getRowIndex(this.bindMdlright);
          this.$nextTick(() => {
            this.$refs.inputmdlname.$refs.input.focus();
          });
        })
        .catch(err => {
          this.loadingDetailEdit = false;
        });
    },
    ShowDetail() {
      var mdlid = 0;
      if (this.bindMdlright.bindmdlid) mdlid = this.bindMdlright.bindmdlid;
      else mdlid = 0;
      this.loadingDetail = true;
      this.$tool
        .request({
          url: "LIS/LIS1/LIS115",
          method: "post",
          data: {
            action: "querydetail",
            bindmdlid: mdlid
          }
        })
        .then(res => {
          this.tableColumnDetail = res.Cols;
          var cotaindata = res.Data;
          for (var i = 0; i < cotaindata.length; i++) {
            cotaindata[i].invalid = cotaindata[i].invalid > 0 ? "停用" : "";
          }
          this.tableDataDetail = cotaindata;
          this.loadingDetail = false;
        })
        .catch(err => {
          this.loadingDetail = false;
        });
    },
    handleTabClick(tab, event) {
      if (tab.label == "合并模板明细") {
        this.curtabindex = 1;
        this.ShowDetail();
      }
    },
    findList() {
      this.loading = true;
      this.$tool
        .request({
          url: "LIS/LIS1/LIS115",
          method: "post",
          data: {
            action: "query"
          }
        })
        .then(res => {
          if (res.Data.length) {
            this.isFirstLoading = true;
            this.tableColumn = res.Cols; //this.ColAchieve(res.Cols);
            var cotaindata = res.Data;
            cotaindata = cotaindata.sort((a, b) => a.invalid - b.invalid);
            for (var i = 0; i < cotaindata.length; i++) {
              cotaindata[i].invalidflag = cotaindata[i].invalid > 0 ? true : false;
              cotaindata[i].invalid = cotaindata[i].invalid > 0 ? "停用" : "";
              cotaindata[i].keepinoldflag = cotaindata[i].keepinold > 0 ? true : false;
              cotaindata[i].keepinold = cotaindata[i].keepinold > 0 ? "是" : "否";
              cotaindata[i].bindmode = cotaindata[i].bindmode == 1 ? "同项合并" : "异项合并";
              if (this.NewArr.indexOf(cotaindata[i].bindmdlid + "") > -1) {
                cotaindata[i].isadd = "1";
              } else {
                cotaindata[i].isadd = "0";
              }
            }
            cotaindata.sort((a, b) => a.isadd - b.isadd);
            this.tableData = cotaindata;
            if (this.curtabindex == 1) {
              this.ShowDetail();
            }
            this.loading = false;
          } else {
            this.tableData = [];
            this.loading = false;
          }
        })
        .catch(err => {
          this.loading = false;
        });
    },
    //保存数据
    SaveRecord() {
      if (this.actionflag < 3) {
        var record = this.$refs.xTable3.tableData;
        record = record.sort((a, b) => a.seq - b.seq);
        for (let i = 0, len = record.length; i < len; i++) {
          record[i].seq = (i + 1) * 10;
        }
        var records = this.$refs.xTable3.getRecordset();
        if (records.insertRecords.length > 0) records.insertRecords = this.SetInvald(records.insertRecords);
        if (records.removeRecords.length > 0) records.removeRecords = this.SetInvald(records.removeRecords);
        if (records.updateRecords.length > 0) records.updateRecords = this.SetInvaldUp(records.updateRecords);
        var savedata = JSON.parse(JSON.stringify(this.bindMdl));
      } else {
        var savedata = JSON.parse(JSON.stringify(this.bindMdlright));
      }

      savedata.invalid = savedata.invalid ? "1" : "0";
      savedata.keepinold = savedata.keepinold ? "1" : "0";
      savedata.bindmode = savedata.bindmode == "同项合并" ? "1" : "2";
      this.$tool
        .request({
          url: "LIS/LIS1/LIS115",
          method: "post",
          data: {
            action: "save",
            utype: this.actionflag,
            saveinfo: savedata,
            urec: records,
            oldinfo: this.tempbindMdl
          }
        })
        .then(res => {
          if (res.errcode == 1) {
            if (this.actionflag < 3) {
              this.$message({
                message: "保存成功",
                type: "success"
              });
              this.AddArray = res.keyid + "";
              if (this.actionflag == 1) this.NewArr.push(res.keyid + "");
              else if (this.actionflag == 2) this.UpdateArr.push(res.keyid + "");
              this.dialogFormVisible = false;
              this.findList();
            } else {
              this.$message({
                message: "删除成功",
                type: "success"
              });
              var delrow = this.$refs.xTable.getCurrentRow();
              if (delrow) {
                var alld = this.$refs.xTable.tableData;
                var rowindex = alld.indexOf(delrow);
                this.$refs.xTable.remove(delrow);
                var allrowindex = this.tableData.indexOf(delrow);
                this.tableData.splice(allrowindex, 1);
                let havedata = this.$refs.xTable.tableData;
                if (havedata.length > 0) {
                  if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                  let selectrow = havedata[rowindex];
                  this.$refs.xTable.setCurrentRow(selectrow);
                  this.bindMdlright = selectrow;
                  this.Delmdlname = selectrow.mdlname;
                }
              } else {
                this.bindMdlright = {};
              }
              if (this.curtabindex == 1) {
                this.ShowDetail();
              }
              this.dialogVisible = false;
            }
          } else {
            this.$message.error("保存失败:" + res.errmsg);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    //添加一条记录
    AddRecord() {
      this.CotainAddNum = this.CotainAddNum + 1;
      let row = {
        rpt_itemcode: "",
        invlid: false,
        seq: this.CotainAddNum * 10
      };
      this.$refs.xTable3.insert(row);
      var curow = this.$refs.xTable3.getTableData().fullData[this.$refs.xTable3.getTableData().fullData.length - 1];
      this.$refs.xTable3.setCurrentRow(curow);
      this.$nextTick(() => {
        var nowtablelength = this.$refs.xTable3.tableData.length;
        var nownum = (nowtablelength - 1) * 2;
        this.$refs.xTable3.$refs.tableBody.$children[nownum].$refs.ddlrptitemSelect.focus();
      });
    },
    DelRecord() {
      var delrow = this.$refs.xTable3.getCurrentRow();
      if (this.DelIndex < 0) this.DelIndex = this.$refs.xTable3.getRowIndex(delrow);
      this.$refs.xTable3.remove(delrow);
      if (this.DelIndex > -1 && this.$refs.xTable3.tableData.length > 0) {
        if (this.$refs.xTable3.getTableData().fullData.length > this.DelIndex) this.DelIndex = this.DelIndex;
        else this.DelIndex = this.DelIndex - 1;
        var selectrow = this.$refs.xTable3.getTableData().fullData[this.DelIndex];

        this.$nextTick(() => {
          this.$refs.xTable3.setCurrentRow(selectrow);
          var nownum = this.DelIndex * 2;
          this.$refs.xTable3.$refs.tableBody.$children[nownum].$refs.ddlrptitemSelect.focus();
        });
      } else {
        var nowdata = this.$refs.xTable3.getTableData().fullData.filter(item => {
          return item._XID < delrow._XID;
        });
        if (nowdata.length > 0) {
          var selectrow = nowdata[nowdata.length - 1];
          this.$nextTick(() => {
            this.$refs.xTable3.setCurrentRow(selectrow);
            var nownum = (nowdata.length - 1) * 2;
            this.$refs.xTable3.$refs.tableBody.$children[nownum].$refs.ddlrptitemSelect.focus();
          });
        }
      }
    },
    SetInvald(records) {
      for (let i = 0, len = records.length; i < len; i++) {
        records[i].invalid = records[i].invalid ? 1 : 0;
      }
      return records;
    },
    SetInvaldUp(records) {
      for (let i = 0, len = records.length; i < len; i++) {
        records[i].cdata.invalid = records[i].cdata.invalid ? 1 : 0;
        records[i].odata.invalid = records[i].odata.invalid ? 1 : 0;
      }
      return records;
    },
    ExportCsv() {
      this.$refs.xTable.exportCsv();
      //this.$refs.tabs.$children[0].$el.children[0].children[0].children[1].className = "el-tabs__item is-top is-chosen";
    },

    RptChangeEvent(code, row, rowIndex) {
      row.rpt_itemcode = code;
      //var currentrow = this.$refs.xTable3.getCurrentRow();
      //this.$refs.xTable3.setSelectCell(currentrow, "invalidflag");
      this.rptfocusflag = true;
    },

    mdlnameChange(value) {
      var pinyinres = this.$pinyin(value, {
        style: this.$pinyin.STYLE_FIRST_LETTER, // 首字母
        heteronym: true
      });
      var inputcode = "";
      for (var i = 0, len = pinyinres.length; i < len; i++) {
        if (pinyinres[i].length > 1) {
          pinyinres[i].sort();
        }
        inputcode += pinyinres[i][0];
      }
      this.bindMdl.inputcode = inputcode.toLocaleUpperCase();
    },
    autofocusEvent(event, element, row, rowIndex) {
      if (element == "mdlname") {
        this.$refs.inputrptitem.$refs.ddlrptitemSelect.focus();
      }
      if (element == "rptitem") {
        this.$refs.inputseq.focus();
      }
      if (element == "seq") {
        this.$refs.inputdesc.focus();
      }
      if (element == "childrptitem") {
        if (this.rptfocusflag) {
          this.$refs.xTable3.$refs.tableBody.$children[rowIndex * 2 + 1].$el.focus();
          this.rptfocusflag = false;
        }
      }
      if (element == "invalid") {
        this.$refs.xTable3.setActiveCell(row, "seq");
        this.rptfocusflag = false;
      }
    },
    containeditclose({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex, cell }) {
      var nowtablelength = this.$refs.xTable3.tableData.length;
      if (column.property == "seq") {
        var thisrow = this.$refs.xTable3.tableData[rowIndex + 1];
        if (!thisrow.seq) thisrow.seq = this.$refs.xTable3.tableData.length * 10;
        if (thisrow.bindmdlid) {
          this.$nextTick(() => {
            this.$refs.xTable3.clearSelected();
            this.$refs.xTable3.clearActived();
            this.$refs.xTable3.setCurrentRow(thisrow);
            this.$nextTick(() => {
              this.$refs.xTable3.$refs.tableBody.$children[(rowIndex + 1) * 2].$refs.ddlrptitemSelect.focus();
            });
          });
        }
      }
      if (column.property == "rpt_itemcode") {
        this.$refs.xTable3.$refs.tableBody.$children[rowIndex * 2 + 1].$el.focus();
      }
    },
    rptfocus() {
      this.rptfocusflag = true;
    },
    bindmodeChange(event) {
      if (event == "同项合并") {
        this.itemname = "合并前项目";
        this.itemnametable = "合并后报告项目";
      } else {
        this.itemname = "目标标本项目";
        this.itemnametable = "参与合并项目";
      }
    }
  }
};
</script>

<style scoped>
::v-deep .Update {
  color: #5050fa;
}

::v-deep .Add {
  color: #b47c7c;
}

::v-deep .vxe-input--wrapper .vxe-input {
  height: auto;
  width: 200px;
  border-radius: 0px;
}

::v-deep .el-button--default.btn-custom-cancel {
  float: right !important;
  margin-left: 10px;
}

.pagetop {
  left: 0;
  right: 0;
  height: 36px;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  text-align: right;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 40px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  right: 485px;
  left: 0;
}

.middle-right {
  background-color: chartreuse;
  position: absolute;
  top: 0;
  bottom: 2px;
  overflow: visible;
  width: 480px;
  right: 0px;
}

table tr td:nth-child(odd) {
  text-align: right;
  white-space: nowrap;
}

table tr td:nth-child(even) {
  text-align: left;
}

table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}

::v-deep .el-tabs__item.is-chosen {
  color: red !important;
}

::v-deep .el-checkbox__inner::after {
  border: 2px solid #000000 !important;
  box-sizing: content-box;
  content: "";
  border-left: 0 !important;
  border-top: 0 !important;
  height: 7px;
  left: 4px;
  position: absolute;
  top: 1px;
  transform: rotate(45deg) scaleY(0);
  width: 3px;
  transition: transform 0.15s ease-in 0.05s;
  transform-origin: center;
}

::v-deep .el-checkbox__input.is-disabled+span.el-checkbox__label {
  color: #000000;
  cursor: not-allowed;
}

::v-deep  .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner+.el-input.is-disabled .el-input__inner {
  background-color: #ffffff !important;
}</style>
